package cz.mpelant.msoe.mealchecker.parser;

import java.util.regex.MatchResult;
import java.util.regex.Pattern;

import cz.mpelant.msoe.mealchecker.data.Plan;
import cz.mpelant.msoe.mealchecker.data.Plans;

public class OverviewParser extends Parser{
	

	
	private static String parseCode(String a){
		return getMatch(a, Pattern.compile("QuickHistory[^']*'([^']+)'", Pattern.MULTILINE | Pattern.DOTALL)).group(1);
	}
	private static Plan getPlan(String data, String codeToSearch){
		MatchResult mr=  getMatch(data, Pattern.compile(tr+td+"("+a+")"+"("+nonTag+codeToSearch+nonTag+")"+aEnd+tdEnd+td+"("+nonTag+")"+tdEnd+trEnd, Pattern.MULTILINE | Pattern.DOTALL));
		Plan p = new Plan();
		p.code=parseCode(mr.group(1)).trim();
		p.name=mr.group(2).trim();
		p.amount=mr.group(3).trim();
		
		return p;
	}
	public static Plans getPlans(String source){
		String data = getData(source);
		Plans plans = new Plans();
		plans.svc = getPlan(data, "SVC");
		plans.meals = getPlan(data, "Meals");
		plans.raider = getPlan(data, "Raider Plan");
		
		return plans;
	}
}
